package com.nuaa.ojjudgecodesandbox.controller;

import com.nuaa.ojjudgecodesandbox.JavaNativeCodeSandbox;
import com.nuaa.ojjudgecodesandbox.model.ExecuteCodeRequest;
import com.nuaa.ojjudgecodesandbox.model.ExecuteCodeResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author ortonzhu
 * @Date 2024/10/19 14:52
 */
@RestController
@RequestMapping("/")
public class MainController {
    @Resource
    private JavaNativeCodeSandbox javaNativeCodeSandbox;
    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }

    @PostMapping("/executeCode")
    ExecuteCodeResponse executeCode (@RequestBody ExecuteCodeRequest executeCodeRequest){
        if(executeCodeRequest==null){
            throw new RuntimeException("请求参数为空");
        }
        return javaNativeCodeSandbox.executeCode(executeCodeRequest);
    }
}
